package sbc.corso;


import corso.lang.CorsoConnection;
import corso.lang.CorsoData;
import corso.lang.CorsoDataException;
import corso.lang.CorsoShareable;
import corso.lang.CorsoVarOid;

public class PlatineSharable implements CorsoShareable {
	
	public String myId;
	public SensorSharable myFirstSensor;
    public SensorSharable mySecondSensor;
    public String Status;
    private static final String shareableStructName = new String("MYSHAREABLEPLATINE"); 
		
	public PlatineSharable (String id, SensorSharable fs, SensorSharable ss, String Status) {	
		this.myId=id;
		this.myFirstSensor = fs;
		this.mySecondSensor = ss;
		this.Status = Status;
	} 
	  
    public PlatineSharable (CorsoVarOid oid) {
        try {
            oid.setTimeStamp (0);
            oid.readShareable (this, null, CorsoConnection.NO_TIMEOUT);
        }
        catch (Exception e) {
            System.exit (-9);
        }
    }
	
	/** 
	 * Method which is called, if you read the structure from an oid 
	 * 
	 * @param data            CorsoData object from which the data is read 
	 * 
	 * @return                none 
	 * 
	 */ 
    public void read (CorsoData data) throws CorsoDataException { 
	    StringBuffer structName = new StringBuffer (""); 
	 
	    // first get the structure information ************************************ 
	    int arity = data.getStructTag (structName); 
	    if (arity != 4) { 
	    	System.out.println ("arity of data is " + arity); 
	    	throw new CorsoDataException (); 
	    } 
	 
	    // here we also check the name of the structure *************************** 
	    if (!structName.toString ().equals (shareableStructName)){ 
	    	throw new CorsoDataException (); 
	    } 
	 
	    // reading value from data ************************************************ 
	    myId= data.getString (); 
	    data.getShareable(myFirstSensor);
	    data.getShareable(mySecondSensor); 
	    Status = data.getString();
    }
	 
	/** 
	 * Method which is called, if you write the structure to an oid 
	 * 
	 * @param data            CorsoData object to which the data is written 
	 * 
	 * @return                none 
	 * 
	 */ 
    public void write (CorsoData data) throws CorsoDataException { 
		System.out.println("PlatineSharable write begin");
	    // first put the structure information ************************************ 
	    data.putStructTag (shareableStructName, 4); 
	    
	    // write values to data *************************************************** 
	    //data.putInt (i1); 
	    data.putString (myId); 
	    data.putShareable(myFirstSensor);
	    data.putShareable(mySecondSensor);
	    data.putString(Status);
	    System.out.println("PlatineSharable write end");
    } 
}